<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@include file="../common/jspcommon.jsp"%>
<%@include file="../common/jscss.jsp"%>
<script type="text/javascript">

	$.ligerDefaults.Grid.editors['textarea'] = {
        create: function (container, editParm){
            var input = $("<textarea />");
            container.append(input);
            container.width('auto').height('auto');
            return input;
        },
        getValue: function (input, editParm){
            return input.val();
        },
        setValue: function (input, value, editParm){
            input.val(value);
        },
        resize: function (input, width, height, editParm){
            var column = editParm.column;
            input.width(column.editor.width);
            input.height(column.editor.height);
        }
    };
	
	
	var grid_ae = null;
	var dialog_ae = null;
	$(function(){
		grid_ae = $("#company_grid").ligerGrid({
                columns: [
                { display: '公司名ID', name: 'id', isSort : false, width: 100},
                { display: '公司名称', name: 'name', isSort : false, width: 200,editor: { type: 'text'}},
                { display: '公司电话', name: 'phone', isSort : false, width: 100,editor: { type: 'text'}},
                { display: '公司地址', name: 'address', isSort : false, width: 200,editor: { type: 'text'}},
                { display: '排序', name: 'sort', isSort : false, width: 100,editor: { type: 'text'}},
                { display: '公司简介', name: 'intro',isSort : false, width: 300,
               	 render: function(record, rowindex, value, column){
                	 return "<span title='"+value+"'>"+value+"</span>";
                  },
                  editor: { type: 'textarea',height:80,width:400}
                },
                { display: '创建人', name: 'creator',isSort : false, width: 100},
                { display: '最后修改人', name: 'updater',isSort : false, width: 100},
                { display: '最后修改时间', name: 'gmtModified',isSort : false,
                  render: function(record, rowindex, value, column){
                	 return (new Date(value.time)).format("yyyy年MM月dd日 hh:mm:ss");
                  }
                }
                ], 
                toolbar: { items: [
                                   { text: '增加', click: addCompany, icon: 'add' }
                                   ]
                                   },
                pageSize:10,
                root :'list',
                record:'totalRecord',
                url: "/misc/company/companyGrid.htm", 
                width: '99%',height:'99%',
                rownumbers:true,
                enabledEdit: true,
                frozen:false,
                detailToEdit: true,
                onAfterSubmitEdit:onAfterSubmitEdit
            });


	});
	
	function addCompany(){
		dialog_ae = $.ligerDialog.open({ height: 600,width:600, url: "/misc/company/addCompany.htm", showMax:true,showMin:true,isResize:true,title:'新增公司'});
	}
	function search(){
		grid_ae.options.parms = [{name:'companyName',value:$("#companyName").val()}];
		grid_ae.loadData();
	}
	
	function onAfterSubmitEdit(e){
		var id = e.record.id;
		var name = e.newdata.name;
		var phone = e.newdata.phone;
		var address = e.newdata.address;
		var intro = e.newdata.intro;
		var sort = e.newdata.sort;
		$.post("saveCompany.htm",{
			id:id,
			name:name,
			phone:phone,
			address:address,
			intro:intro,
			sort:sort
		},function(data){
		});
	}
</script>
<table>
	<tr>
		<td>公司名：</td>
		<td><%@include file="companyName.jsp" %></td>
		<td><input id="btnOK" type="button" value="查询" onclick="search()" /></td>
	</tr>
</table>
<div id="company_grid" style="margin:0; padding:0"></div>
